package org.cuatrovientos.erp.business;

import java.util.List;

import org.apache.log4j.Logger;
import org.cuatrovientos.erp.dao.ProductDAOInterface;
import org.cuatrovientos.erp.model.Product;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Holds all the business logic for product related management
 * @author VB
 */
public class ProductBO implements ProductBOInterface {
	
	// Get log4j logger
	private static final Logger logger = Logger.getLogger(ProductBO.class);
	
	@Autowired
    private ProductDAOInterface productDAO;

	@Override
	public Product selectById(int id) {
		logger.info("selectById: " + id);
		return productDAO.selectById(id);
	}

	@Override
	public List<Product> selectAll() {
		logger.info("selectAll: ");
		return productDAO.selectAll();
	}

	@Override
	public List<Product> searchByName(String name) {
		logger.info("search : " + name);
		return productDAO.searchByName(name);
	}
	
	@Override
	public List<Product> searchByDescription(String description) {
		logger.info("search : " + description);
		return productDAO.searchByDescription(description);
	}

	@Override
	public void deleteById(int id) {
		logger.info("delete: " + id);
		productDAO.deleteById(id);
	}

	@Override
	public void insert(Product product) {
		logger.info("insert: " + product);
		productDAO.insert(product);
	}

	@Override
	public void update(Product product) {
		logger.info("update: " + product);
		productDAO.update(product);
	}
	
	public void delete(Product product){
		logger.info("delete: " + product);
		productDAO.delete(product);
	}
}
